package com.victor.bookretail.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.victor.bookretail.domain.OrderInfoSearchBo;
import com.victor.bookretail.entity.OrderInfoPo;
import com.victor.bookretail.mapper.OrderInfoMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Repository
public class OrderInfoRepository {

    @Resource
    private OrderInfoMapper mapper;

    public OrderInfoPo insert(OrderInfoPo orderInfoPo) {
        mapper.insert(orderInfoPo);
        return orderInfoPo;
    }

    public List<OrderInfoPo> query(OrderInfoSearchBo searchBo) {
        QueryWrapper<OrderInfoPo> queryWrapper = new QueryWrapper<>();
        boolean valid = false;
        if (!Objects.isNull(searchBo.getUserId())) {
            queryWrapper.eq("user_id", searchBo.getUserId());
            valid = true;
        }
        if (!valid) {
            return new ArrayList<>();
        }
        return mapper.selectList(queryWrapper);
    }

}
